let mockProjects = [
  {
    id: 1,
    name: '项目A',
    uniqueId: 'PROJ-001',
    createTime: '2025-01-15',
    fileCount: 42
  },
  {
    id: 2,
    name: '项目B',
    uniqueId: 'PROJ-002',
    createTime: '2025-03-20',
    fileCount: 28
  }
]

export const mockProjectList = mockProjects

export function mockAddProject(project) {
  // 获取当前最大ID
  const maxId = mockProjects.reduce((max, p) => Math.max(max, p.id), 0)
  const newProject = {
    id: maxId + 1,
    name: project.projName,
    uniqueId: project.projKey,
    createTime: new Date().toISOString().split('T')[0],
    fileCount: 0
  }
  mockProjects.push(newProject)
  return {
    data: newProject,
    list: [...mockProjects]
  }
}

export function mockUpdateProject(data) {
  return new Promise((resolve) => {
    setTimeout(() => {
      const index = mockProjects.findIndex(p => p.id === data.id)
      if (index !== -1) {
        mockProjects[index].name = data.name
        resolve({
          data: true,
          list: [...mockProjects]
        })
      } else {
        resolve({ data: false })
      }
    }, 500)
  })
}

export function mockDeleteProject(id) {
  const index = mockProjects.findIndex(p => p.id === id)
  if (index !== -1) {
    mockProjects.splice(index, 1)
    // 重新排序ID
    mockProjects.forEach((p, i) => {
      p.id = i + 1
    })
    return {
      data: true,
      list: [...mockProjects]
    }
  }
  return { data: false }
}

export const mockFileStats = [
  // 项目A的文件类型分布
  { value: 15, name: '需求', projectId: 'PROJ-001' },
  { value: 20, name: '测试用例', projectId: 'PROJ-001' },
  { value: 7, name: '模型', projectId: 'PROJ-001' },
  { value: 5, name: '测试报告', projectId: 'PROJ-001' },

  // 项目B的文件类型分布
  { value: 8, name: '需求', projectId: 'PROJ-002' },
  { value: 12, name: '测试用例', projectId: 'PROJ-002' },
  { value: 5, name: '模型', projectId: 'PROJ-002' },
  { value: 3, name: '测试报告', projectId: 'PROJ-002' }
]

export function mockGetProjectFileStats(projectId) {
  return {
    code: 200,
    data: mockFileStats.filter(item => item.projectId === projectId)
  }
}
